(function(){"use strict";BX.namespace("BX.Landing");var n=BX.Landing.Utils.onAnimationEnd;var e=BX.Landing.Utils.htmlToElement;var t=BX.Landing.Utils.deepFreeze;var i=BX.Landing.Utils.fireCustomEvent;var o=BX.Landing.Utils.isPlainObject;var a=BX.Landing.Utils.isEmpty;var r=BX.Landing.Utils.isBoolean;var s=BX.Landing.Utils.addClass;var c=BX.Landing.Utils.removeClass;var l=BX.Landing.Utils.hasClass;var d=BX.Landing.Utils.append;var u=BX.Landing.Utils.prepend;var h=BX.Landing.Utils.insertAfter;var g=BX.Landing.Utils.remove;var B=BX.Landing.Utils.slice;var k=BX.Landing.Utils.data;var f=BX.Landing.Utils.arrayUnique;var L=BX.Landing.Utils.create;var b=BX.Landing.Utils.delay;var m=BX.Landing.UI.Button.Plus;var p=BX.Landing.UI.Panel.Content;var v="ru";var y="by";var A="kz";var T="la";var X="de";var w="br";var E="ua";function C(n){return!!n&&!!n.querySelector(".block-wrapper")}function S(n){return!!n&&!!n.querySelector('button[data-id="insert_first_block"]')}BX.Landing.Main=function(n){var e=BX.Landing.Env.getInstance().getOptions();this.id=n;this.options=t(e);this.blocksPanel=null;this.currentBlock=null;this.loadedDeps={};this.onSliderFormLoaded=this.onSliderFormLoaded.bind(this);this.onBlockDelete=this.onBlockDelete.bind(this);BX.addCustomEvent("Landing.Block:onAfterDelete",this.onBlockDelete);this.adjustEmptyAreas();if(this.options.blocks){if(!this.blocksPanel){this.blocksPanel=this.createBlocksPanel();this.onBlocksListCategoryChange("last");this.blocksPanel.layout.hidden=true;d(this.blocksPanel.layout,document.body)}this.blocksPanel.content.hidden=false}BX.Landing.UI.Panel.StatusPanel.setLastModified(e.lastModified);BX.Landing.UI.Panel.StatusPanel.getInstance().show()};BX.Landing.Main.TYPE_PAGE="PAGE";BX.Landing.Main.TYPE_STORE="STORE";BX.Landing.getMode=function(){return"edit"};BX.Landing.Main.instance=null;BX.Landing.Main.createInstance=function(n){top.BX.Landing.Main.instance=new BX.Landing.Main(n)};BX.Landing.Main.getInstance=function(){if(top.BX.Landing.Main.instance){return top.BX.Landing.Main.instance}top.BX.Landing.Main.instance=new BX.Landing.Main(-1);return top.BX.Landing.Main.instance};BX.Landing.Main.prototype={hideBlocksPanel:function(){if(this.blocksPanel){return this.blocksPanel.hide()}return Promise.resolve()},getLayoutAreas:function(){if(!this.layoutAreas){this.layoutAreas=[].concat(B(document.body.querySelectorAll(".landing-header")),B(document.body.querySelectorAll(".landing-sidebar")),B(document.body.querySelectorAll(".landing-main")),B(document.body.querySelectorAll(".landing-footer")))}return this.layoutAreas},createInsertBlockButton:function(n){var e=new m("insert_first_block",{text:BX.Landing.Loc.getMessage("ACTION_BUTTON_CREATE")});e.on("click",this.showBlocksPanel.bind(this,null,n,e));e.on("mouseover",this.onCreateButtonMouseover.bind(this,n,e));e.on("mouseout",this.onCreateButtonMouseout.bind(this,n,e));return e},onCreateButtonMouseover:function(n,e){if(l(n,"landing-header")||l(n,"landing-footer")){var t=this.getLayoutAreas();if(t.length>1){switch(true){case l(n,"landing-main"):e.setText([BX.Landing.Loc.getMessage("ACTION_BUTTON_CREATE"),BX.Landing.Loc.getMessage("LANDING_ADD_BLOCK_TO_MAIN")].join(" "));break;case l(n,"landing-header"):e.setText([BX.Landing.Loc.getMessage("ACTION_BUTTON_CREATE"),BX.Landing.Loc.getMessage("LANDING_ADD_BLOCK_TO_HEADER")].join(" "));break;case l(n,"landing-sidebar"):e.setText([BX.Landing.Loc.getMessage("ACTION_BUTTON_CREATE"),BX.Landing.Loc.getMessage("LANDING_ADD_BLOCK_TO_SIDEBAR")].join(" "));break;case l(n,"landing-footer"):e.setText([BX.Landing.Loc.getMessage("ACTION_BUTTON_CREATE"),BX.Landing.Loc.getMessage("LANDING_ADD_BLOCK_TO_FOOTER")].join(" "));break}clearTimeout(this.fadeTimeout);this.fadeTimeout=setTimeout(function(){s(n,"landing-area-highlight");t.forEach(function(e){if(e!==n){s(e,"landing-area-fade")}},this)}.bind(this),400)}}},onCreateButtonMouseout:function(n,e){clearTimeout(this.fadeTimeout);if(l(n,"landing-header")||l(n,"landing-footer")){var t=this.getLayoutAreas();if(t.length>1){e.setText(BX.Landing.Loc.getMessage("ACTION_BUTTON_CREATE"));t.forEach(function(n){c(n,"landing-area-highlight");c(n,"landing-area-fade")},this)}}},initEmptyArea:function(n){if(n){n.innerHTML="";d(this.createInsertBlockButton(n).layout,n);s(n,"landing-empty")}},destroyEmptyArea:function(n){if(n){var e=n.querySelector('button[data-id="insert_first_block"]');if(e){g(e)}c(n,"landing-empty")}},adjustEmptyAreas:function(){this.getLayoutAreas().filter(function(n){return C(n)&&S(n)}).forEach(this.destroyEmptyArea,this);this.getLayoutAreas().filter(function(n){return!C(n)&&!S(n)}).forEach(this.initEmptyArea,this);var n=document.body.querySelector("main.landing-edit-mode");var e=!this.getLayoutAreas().some(C);if(n){if(e){s(n,"landing-empty");return}c(n,"landing-empty")}},enableControls:function(){c(document.body,"landing-ui-hide-controls")},disableControls:function(){s(document.body,"landing-ui-hide-controls")},isControlsEnabled:function(){return!l(document.body,"landing-ui-hide-controls")},appendBlock:function(t,i){var o=e(t.content);o.id="block"+t.id;if(!i){s(o,"landing-ui-show");n(o,"showBlock").then(function(){c(o,"landing-ui-show")})}this.insertToBlocksFlow(o);return o},showBlocksPanel:function(n,e,t){this.currentBlock=n;this.currentArea=e;this.blocksPanel.show();if(!!e&&!!t){this.onCreateButtonMouseout(e,t)}},createBlocksPanel:function(){var n=this.options.blocks;var e=Object.keys(n);var t=new p("blocks_panel",{title:BX.Landing.Loc.getMessage("LANDING_CONTENT_BLOCKS_TITLE"),className:"landing-ui-panel-block-list",scrollAnimation:true});e.forEach(function(e){var i=!a(n[e].items);var o=e==="popular";var r=n[e].separator;if(i&&!o||r){t.appendSidebarButton(this.createBlockPanelSidebarButton(e,n[e]))}},this);t.appendSidebarButton(new BX.Landing.UI.Button.SidebarButton("feedback_button",{className:"landing-ui-button-sidebar-feedback",text:BX.Landing.Loc.getMessage("LANDING_BLOCKS_LIST_FEEDBACK_BUTTON"),onClick:this.showFeedbackForm.bind(this)}));return t},showSliderFeedbackForm:function(n){if(!this.sliderFeedbackInited){this.sliderFeedbackInited=true;this.sliderFeedback=new p("slider_feedback",{title:BX.Landing.Loc.getMessage("LANDING_PANEL_FEEDBACK_TITLE"),className:"landing-ui-panel-feedback"});d(this.sliderFeedback.layout,document.body);this.sliderFormLoader=new BX.Loader({target:this.sliderFeedback.content});this.sliderFormLoader.show();this.initFeedbackForm()}n=o(n)?n:{};n.bitrix24=this.options.server_name;n.siteId=this.options.site_id;n.siteUrl=this.options.url;n.siteTemplate=this.options.xml_id;n.productType=this.options.productType||"Undefined";var e=this.getFeedbackFormOptions();b24formFeedBack({id:e.id,lang:e.lang,sec:e.sec,type:"slider_inline",node:this.sliderFeedback.content,handlers:{load:this.onSliderFormLoaded.bind(this)},presets:o(n)?n:{}});this.sliderFeedback.show()},getFeedbackFormOptions:function(){var n=BX.Landing.Loc.getMessage("LANGUAGE_ID");var e={id:"16",sec:"3h483y",lang:"en"};switch(n){case v:case y:case A:e={id:"8",sec:"x80yjw",lang:"ru"};break;case T:e={id:"14",sec:"wu561i",lang:"la"};break;case X:e={id:"10",sec:"eraz2q",lang:"de"};break;case w:e={id:"12",sec:"r6wvge",lang:"br"};break;case E:e={id:"18",sec:"d9e09o",lang:"ua"};break}return e},onSliderFormLoaded:function(){this.sliderFormLoader.hide()},showFeedbackForm:function(){this.showSliderFeedbackForm({target:"blocksList"})},initFeedbackForm:function(){(function(n,e,t,i){n["Bitrix24FormObject"]=i;n[i]=n[i]||function(){arguments[0].ref=t;(n[i].forms=n[i].forms||[]).push(arguments[0])};if(n[i]["forms"])return;var o=e.createElement("script");var a=1*new Date;o.async=1;o.src=t+"?"+a;var r=e.getElementsByTagName("script")[0];r.parentNode.insertBefore(o,r)})(window,document,"https://landing.bitrix24.ru/bitrix/js/crm/form_loader.js","b24formFeedBack")},createBlockPanelSidebarButton:function(n,e){return new BX.Landing.UI.Button.SidebarButton(n,{text:e.name,child:!e.separator,className:e.new?"landing-ui-new-section":"",onClick:this.onBlocksListCategoryChange.bind(this,n)})},onBlocksListCategoryChange:function(n){this.blocksPanel.content.hidden=false;this.blocksPanel.sidebarButtons.forEach(function(e){e.layout.classList[e.id===n?"add":"remove"]("landing-ui-active")});this.blocksPanel.content.innerHTML="";if(n==="last"){if(!this.lastBlocks){this.lastBlocks=Object.keys(this.options.blocks["last"].items)}this.lastBlocks=f(this.lastBlocks);this.lastBlocks.forEach(function(n){var e=this.getBlockFromRepository(n);this.blocksPanel.appendCard(this.createBlockCard(n,e))},this);return}Object.keys(this.options.blocks[n].items).forEach(function(e){var t=this.options.blocks[n].items[e];this.blocksPanel.appendCard(this.createBlockCard(e,t))},this);if(this.blocksPanel.content.scrollTop){requestAnimationFrame(function(){this.blocksPanel.content.scrollTop=0}.bind(this))}},getBlockFromRepository:function(n){var e=this.options.blocks;var t=Object.keys(e);var i=t.find(function(t){return n in e[t].items});if(i){return e[i].items[n]}},onCopyBlock:function(n){window.localStorage.landingBlockId=n.id;window.localStorage.landingBlockName=n.manifest.block.name;window.localStorage.landingBlockAction="copy";try{window.localStorage.requiredUserAction=JSON.stringify(n.requiredUserActionOptions)}catch(n){window.localStorage.requiredUserAction=""}},onCutBlock:function(n){window.localStorage.landingBlockId=n.id;window.localStorage.landingBlockName=n.manifest.block.name;window.localStorage.landingBlockAction="cut";try{window.localStorage.requiredUserAction=JSON.stringify(n.requiredUserActionOptions)}catch(n){window.localStorage.requiredUserAction=""}top.BX.Landing.Block.storage.remove(n);g(n.node);i("Landing.Block:onAfterDelete",[n])},onPasteBlock:function(n){if(window.localStorage.landingBlockId){var e="Landing::copyBlock";if(window.localStorage.landingBlockAction==="cut"){e="Landing::moveBlock"}var t={};t[e]={action:e,data:{lid:n.lid||BX.Landing.Main.getInstance().id,block:window.localStorage.landingBlockId,params:{AFTER_ID:n.id,RETURN_CONTENT:"Y"}}};BX.Landing.Backend.getInstance().batch(e,t,{action:e}).then(function(t){this.currentBlock=n;return this.addBlock(t[e].result.content)}.bind(this))}},addBlock:function(n,e,t){if(this.lastBlocks){this.lastBlocks.unshift(n.manifest.code)}var i=this;var o=this.appendBlock(n,t);return this.loadBlockDeps(n).then(function(n){if(!r(e)||e===false){var t=null;var a=null;if(i.currentBlock){t=i.currentBlock.lid;a=i.currentBlock.id}if(i.currentArea){t=k(i.currentArea,"landing");a=k(i.currentArea,"site")}BX.Landing.History.getInstance().push(new BX.Landing.History.Entry({block:n.id,selector:"#block"+n.id,command:"addBlock",undo:"",redo:{currentBlock:a,lid:t,code:n.manifest.code}}))}i.currentBlock=null;i.currentArea=null;var s=parseInt(n.id);var c=top.BX.Landing.Block.storage.get(s);if(c){g(c.node);top.BX.Landing.Block.storage.remove(c)}new BX.Landing.Block(o,{id:s,active:true,requiredUserAction:n.requiredUserAction,manifest:n.manifest,dynamicParams:n.dynamicParams});return i.runBlockScripts(n).then(function(){return o})}).catch(function(n){console.warn(n)})},onAddBlock:function(n,e,t){e=parseInt(e);this.hideBlocksPanel();return this.showBlockLoader().then(this.loadBlock(n,e)).then(function(n){return b(500,n)}).then(function(n){var e=this.addBlock(n,t);this.adjustEmptyAreas();this.hideBlockLoader();return e}.bind(this))},insertToBlocksFlow:function(n){var e=this.currentBlock&&this.currentBlock.node&&this.currentBlock.node.parentNode;if(e){h(n,this.currentBlock.node);return}u(n,this.currentArea)},getBlockLoader:function(){if(!this.blockLoader){this.blockLoader=new BX.Loader({size:60});this.blockLoaderContainer=L("div",{props:{className:"landing-block-loader-container"},children:[this.blockLoader.layout]})}return this.blockLoaderContainer},showBlockLoader:function(){this.insertToBlocksFlow(this.getBlockLoader());this.blockLoader.show();return Promise.resolve()},hideBlockLoader:function(){g(this.getBlockLoader());this.blockLoader=null;return Promise.resolve()},loadBlockDeps:function(n){var e=BX.processHTML(n.content_ext);if(BX.type.isArray(e.SCRIPT)){e.SCRIPT=e.SCRIPT.filter(function(n){return!n.isInternal})}var t=0;var i=n.js.length+e.SCRIPT.length+e.STYLE.length+n.css.length;var o=null;if(!this.loadedDeps[n.manifest.code]&&i>0){o=new Promise(function(o){function a(){t+=1;t===i&&o(n)}if(i>t){e.SCRIPT.forEach(function(n){if(!n.isInternal){BX.loadScript(n.JS,a)}});e.STYLE.forEach(function(n){BX.loadScript(n,a)});n.css.forEach(function(n){BX.loadScript(n,a)});n.js.forEach(function(n){BX.loadScript(n,a)})}else{a()}this.loadedDeps[n.manifest.code]=true}.bind(this))}else{o=Promise.resolve(n)}return o},runBlockScripts:function(n){return new Promise(function(e){var t=BX.processHTML(n.content).SCRIPT;if(t.length){BX.ajax.processScripts(t,undefined,function(){e(n)})}else{e(n)}})},loadBlock:function(n,e){return function(){var t=this.id;var i=this.options.site_id;if(this.currentBlock){t=this.currentBlock.lid;i=this.currentBlock.siteId}if(this.currentArea){t=k(this.currentArea,"landing");i=k(this.currentArea,"site")}var o={lid:t,siteId:i};var a={ACTIVE:"Y",CODE:n,AFTER_ID:!!this.currentBlock?this.currentBlock.id:0,RETURN_CONTENT:"Y"};if(!e){o.fields=a;return BX.Landing.Backend.getInstance().action("Landing::addBlock",o,{code:n})}else{o={undeleete:{action:"Landing::markUndeletedBlock",data:{lid:t,block:e}},getContent:{action:"Block::getContent",data:{block:e,lid:t,fields:a,editMode:1}}};return BX.Landing.Backend.getInstance().batch("Landing::addBlock",o,{code:n}).then(function(n){n.getContent.result.id=e;return n.getContent.result})}}.bind(this)},createBlockCard:function(n,e,t){return new BX.Landing.UI.Card.BlockPreviewCard({title:e.name,image:e.preview,code:n,mode:t,isNew:e.new===true,onClick:this.onAddBlock.bind(this,n)})},onBlockDelete:function(n){if(!n.parent.querySelector(".block-wrapper")){this.adjustEmptyAreas()}},showOverlay:function(){var n=document.querySelector("main.landing-edit-mode");if(n){s(n,"landing-ui-overlay")}},hideOverlay:function(){var n=document.querySelector("main.landing-edit-mode");if(n){c(n,"landing-ui-overlay")}}}})();
//# sourceMappingURL=landing.map.js